package com.jiazhong.front.controller;

import com.jiazhong.commons.Util.JsonResult;
import com.jiazhong.commons.bean.User;
import com.jiazhong.front.service.AuthService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/auth")
public class AuthController {
    @Resource
    private AuthService authService;

    @PostMapping("/login")
    public JsonResult login(User user) {
        return authService.login(user);
    }

    @DeleteMapping("/logout")
    public JsonResult logout(HttpServletRequest request) {
        return authService.logout(request.getHeader("token"));
    }
    @PostMapping
    public JsonResult save(User user){
        return authService.register(user);
    }
}
